package org.setamv.springcloud.hystrix.raw.command;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class OkHystrixCommand extends HystrixCommand<String> {

    public OkHystrixCommand() {
        super(HystrixCommandGroupKey.Factory.asKey("testGroup"));
    }

    @Override
    protected String run() throws Exception {
        // 使用HttpClient访问url
        String url = "http://setamv.tech:9091/greetings/from/setamv";
        HttpGet httpGet = new HttpGet(url);
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpResponse response = httpClient.execute(httpGet);
        String greetings = EntityUtils.toString(response.getEntity());
        return greetings;
    }
}
